<script>
async function playToTheEnd() {
  const video = document.querySelector('video');
  const result = new Promise(r => video.onended = r);
  video.play();
  return await result;
}

async function playOneFrame() {
  const video = document.querySelector('video');
  const result = new Promise(r => video.onpause = r);
  video.ontimeupdate = () => {
    video.pause();
    video.ontimeupdate = null;
  };
  video.play();
  return await result;
}

async function playNFrames(n) {
  for (let i = 0; i < n; i++)
    await playOneFrame();
}

let _frameCount = -1;
async function countFrames() {
  if (_frameCount === -1) {
    const video = document.querySelector('video');

    if (!video.duration)
      return 0;

    if (video.currentTime)
      await playToTheEnd();

    let count = 0;
    while (true) {
      ++count;
      await playOneFrame();
      if (video.ended)
        break;
    }
    _frameCount = count;
  }
  return _frameCount;
}

async function seekLastFrame() {
  let frameCount = await countFrames();
  await playNFrames(frameCount);
  return frameCount;
}

</script>
<body>
<video controls>
  <source src="v.webm" type="video/webm">
  Your browser does not support HTML video.
</video>
</body>
